Load the libraries
library(ggmap)
## Loading required package: ggplot2
## ℹ Google's Terms of Service: <]8;;https://mapsplatform.google.comhttps://mapsplatform.google.com]8;;>
## ℹ Please cite ggmap if you use it! Use `citation("ggmap")` for details.
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2
## ──
## ✔ tibble 3.1.8 ✔ dplyr 1.1.0
## ✔ tidyr 1.3.0 ✔ stringr 1.5.0
## ✔ readr 2.1.4 ✔ forcats 1.0.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(here)
## here() starts at C:/Users/patel/Dropbox/PC/Documents/Computer_Modeling_SP2023/Patel
library(ggsn)
## Loading required package: grid
register_google(key = "AIzaSyApwNnOfl8RbwOcx6NXsKEmFHhr-AgJiho", write = TRUE)
## ℹ Replacing old key (AIzaSyApwNnOfl8RbwOcx6NXsKEmFHhr) with new key in C:/Users/patel/Dropbox/PC/Documents/.Renviron
Load the data
ChemData<-read_csv(here("Week_07","Data","chemicaldata_maunalua.csv"))
## Rows: 23 Columns: 15
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): Zone, Site, Season, Tide_time
## dbl (11): Waypoint, Lat, Long, Temp_in, Salinity, Phosphate, Silicate, NN, p...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
glimpse(ChemData)
## Rows: 23
## Columns: 15
## $ Waypoint <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,…
## $ Zone <chr> "Transition", "Transition", "Transition", "Transition", "D…
## $ Lat <dbl> 21.27531, 21.27523, 21.27504, 21.27449, 21.27503, 21.27485…
## $ Long <dbl> -157.7618, -157.7627, -157.7633, -157.7640, -157.7617, -15…
## $ Site <chr> "W", "W", "W", "W", "W", "W", "W", "W", "W", "W", "W", "W"…
## $ Season <chr> "SPRING", "SPRING", "SPRING", "SPRING", "SPRING", "SPRING"…
## $ Tide_time <chr> "Low_Day", "Low_Day", "Low_Day", "Low_Day", "Low_Day", "Lo…
## $ Temp_in <dbl> 23.75506, 23.53256, 22.63450, 24.01982, 23.26102, 24.00517…
## $ Salinity <dbl> 27.74029, 30.61192, 28.37008, 32.82124, 29.12293, 34.02018…
## $ Phosphate <dbl> 0.54, 0.36, 0.50, 0.25, 0.50, 0.13, 0.28, 0.15, 0.23, 0.11…
## $ Silicate <dbl> 157.93, 92.59, 143.60, 42.32, 126.47, 15.04, 56.31, 23.10,…
## $ NN <dbl> 7.92, 3.37, 7.29, 0.79, 7.45, 0.46, 1.59, 0.34, 1.91, 0.25…
## $ pH <dbl> 7.909, 7.965, 8.023, 7.995, 8.005, 8.019, 8.003, 7.978, 7.…
## $ TA <dbl> 2161.482, 2145.828, 2272.391, 2219.583, 2151.826, 2216.758…
## $ percent_sgd <dbl> 20.4043928, 11.9625323, 18.5529716, 5.4677003, 16.3397933,…
Get basic map of Oahu.
Oahu<-get_map("Oahu")
## ℹ <]8;;https://maps.googleapis.com/maps/api/staticmap?center=Oahu&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx-AgJihohttps://maps.googleapis.com/maps/api/staticmap?center=Oahu&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx-AgJiho]8;;>
## ℹ <]8;;https://maps.googleapis.com/maps/api/geocode/json?address=Oahu&key=xxx-AgJihohttps://maps.googleapis.com/maps/api/geocode/json?address=Oahu&key=xxx-AgJiho]8;;>
# Use ggmap to plot the base layer
ggmap(Oahu)

Get coordinates for Wailupe on Oahu.
Oahu<-get_map("Oahu")
## ℹ <]8;;https://maps.googleapis.com/maps/api/staticmap?center=Oahu&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx-AgJihohttps://maps.googleapis.com/maps/api/staticmap?center=Oahu&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx-AgJiho]8;;>
## ℹ <]8;;https://maps.googleapis.com/maps/api/geocode/json?address=Oahu&key=xxx-AgJihohttps://maps.googleapis.com/maps/api/geocode/json?address=Oahu&key=xxx-AgJiho]8;;>
# Use ggmap to plot the base layer
ggmap(Oahu)

#Make a data frame of lon and lat coordinates
WP<-data.frame(lon = -157.7621, lat = 21.27427) # coordinates for Wailupe
# Get base layer
Map1<-get_map(WP)
## ℹ <]8;;https://maps.googleapis.com/maps/api/staticmap?center=21.27427,-157.7621&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx-AgJihohttps://maps.googleapis.com/maps/api/staticmap?center=21.27427,-157.7621&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx-AgJiho]8;;>
# plot it
ggmap(Map1)

# Zoom in on a location (3: continent level ---to--- 20: zooooomed in)
Map1<-get_map(WP,zoom = 17)
## ℹ <]8;;https://maps.googleapis.com/maps/api/staticmap?center=21.27427,-157.7621&zoom=17&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx-AgJihohttps://maps.googleapis.com/maps/api/staticmap?center=21.27427,-157.7621&zoom=17&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx-AgJiho]8;;>
ggmap(Map1)

# Change the map type
Map1<-get_map(WP,zoom = 17, maptype = "watercolor")
## ! `maptype = "watercolor"` is only available with `source = "stamen"`; resetting source.
## ℹ <]8;;https://maps.googleapis.com/maps/api/staticmap?center=21.27427,-157.7621&zoom=17&size=640x640&scale=2&maptype=terrain&key=xxx-AgJihohttps://maps.googleapis.com/maps/api/staticmap?center=21.27427,-157.7621&zoom=17&size=640x640&scale=2&maptype=terrain&key=xxx-AgJiho]8;;>
## ℹ Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under CC BY SA.
ggmap(Map1)

Map1<-get_map(WP,zoom = 17, maptype = "satellite")
## ℹ <]8;;https://maps.googleapis.com/maps/api/staticmap?center=21.27427,-157.7621&zoom=17&size=640x640&scale=2&maptype=satellite&language=en-EN&key=xxx-AgJihohttps://maps.googleapis.com/maps/api/staticmap?center=21.27427,-157.7621&zoom=17&size=640x640&scale=2&maptype=satellite&language=en-EN&key=xxx-AgJiho]8;;>
ggmap(Map1)+
geom_point(data = ChemData,
aes(x = Long, y = Lat, color = Salinity),
size = 4) +
scale_color_viridis_c()+
scalebar( x.min = -157.766, x.max = -157.758,
y.min = 21.2715, y.max = 21.2785,
dist = 250, dist_unit = "m", model = "WGS84",
transform = TRUE, st.color = "white",
box.fill = c("yellow", "white"))
## Warning: Removed 2 rows containing missing values (`geom_point()`).
## Warning: Removed 1 rows containing missing values (`geom_text()`).

# Don't know the exact lat and long?
# Use geocode() to get exact locations that you can then use in the maps.
geocode("the white house")
## ℹ <]8;;https://maps.googleapis.com/maps/api/geocode/json?address=the+white+house&key=xxx-AgJihohttps://maps.googleapis.com/maps/api/geocode/json?address=the+white+house&key=xxx-AgJiho]8;;>
## # A tibble: 1 × 2
## lon lat
## <dbl> <dbl>
## 1 -77.0 38.9
geocode("California State University, Northridge")
## ℹ <]8;;https://maps.googleapis.com/maps/api/geocode/json?address=California+State+University,+Northridge&key=xxx-AgJihohttps://maps.googleapis.com/maps/api/geocode/json?address=California+State+University,+Northridge&key=xxx-AgJiho]8;;>
## # A tibble: 1 × 2
## lon lat
## <dbl> <dbl>
## 1 -119. 34.2